import pandas as pd
import matplotlib.pyplot as plt
from wordcloud import WordCloud

df=pd.read_excel(r'D:\doc\电商销售数据08月.xlsx')
groupByInfo=df.groupby(['商品品类'])['销售数'].sum()
groupByInfo=groupByInfo.to_dict()

#创建词云对象
wordcloud=WordCloud(font_path='simhei.ttf',background_color='white').generate_from_frequencies(groupByInfo)

# 使用matplotlib绘制词云图
plt.figure(figsize=(9, 6)) 
plt.imshow(wordcloud, interpolation='bilinear') 
plt.axis("off")

plt.show()